//
//  MSProShowerTopBar.m
//  MS
//
//  Created by Yuan on 13-3-19.
//  Copyright (c) 2013年 He Yuan. All rights reserved.
//

#import "MSProShowerTopBar.h"

@implementation MSProShowerTopBar

- (id)initWithFrame:(CGRect)frame delegate:(id)delegate
{
    self = [super initWithFrame:frame];
    if (self)
    {
        UIImage *barImage = [UIImage imageNamed:@"pro_list_topbar"];
        frame.size = barImage.size;
        self.frame = frame;
        
        UIImageView *barImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, barImage.size.width, barImage.size.height)];
        [barImageView setImage:barImage];
        [self addSubview:barImageView];
        
        //custom segment
        NSDictionary *item1 = [NSDictionary dictionaryWithObjectsAndKeys:HYLocalizedString(@""),@"title",@"pro_topbar_l",@"img", nil];
        NSDictionary *item2 = [NSDictionary dictionaryWithObjectsAndKeys:HYLocalizedString(@""),@"title",@"pro_topbar_m",@"img", nil];
        NSDictionary *item3 = [NSDictionary dictionaryWithObjectsAndKeys:HYLocalizedString(@""),@"title",@"pro_topbar_r",@"img", nil];
        NSArray *items = [NSArray arrayWithObjects:item1,item2,item3, nil];
        CustomSegmentedControl *segment = [[CustomSegmentedControl alloc]initWithFrame:CGRectZero items:items defaultSelectIndex:0];
        segment.delegate = delegate;
        [self addSubview:segment];
        
        UIViewSetFrameOrigin(segment, CGPointMake(10, barImage.size.height/2-segment.frame.size.height/2 - 5));
        
        UIImage *picmode = [UIImage imageNamed:@"pro_picmode"];
        UIImage *listmode = [UIImage imageNamed:@"pro_listmode"];        
        UIButton *modebtn = [MSTool createButton:CGRectMake(segment.frame.origin.x+segment.frame.size.width+7,segment.frame.origin.y+4,picmode.size.width,picmode.size.height) action:@selector(changeMode:) delegate:delegate];
        [modebtn setImage:picmode forState:UIControlStateNormal];
        [modebtn setImage:listmode forState:UIControlStateSelected];
        modebtn.selected = NO;
        [self addSubview:modebtn];
        // Initialization code
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
